﻿using System;
using System.Web.UI.WebControls;
using MaLu.Common;
using MaLu.BusiLogic;
using System.Xml;
using MaLu.Framework.Common;

namespace MaluJg.web.ProjectFund
{
    public partial class Item3v : ProjectPage1
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindData();
            }
        }
        private void BindData()
        {
            string projectname = string.Empty;
            string content = BLProject.GetProjectItem(Provider, ProjectID, "item3.aspx", ref projectname);
            if (content != string.Empty)
            {
                XmlDocument document = new XmlDocument();
                document.LoadXml(content);
                XmlElement xe = document.SelectSingleNode("//招标项目") as XmlElement;
                tbProjectName.Text = Util.ReturnXml(xe.InnerText);
                xe = document.SelectSingleNode("//招标单位") as XmlElement;
                tbZhaobiaoDept.Text = Util.ReturnXml(xe.InnerText);
               
                xe = document.SelectSingleNode("//招标地点") as XmlElement;
                tbPlace.Text = Util.ReturnXml(xe.InnerText);

                xe = document.SelectSingleNode("//招标阶段") as XmlElement;

                string[] items = xe.InnerText.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
                foreach (string item in items)
                {
                   ListItem li = cbZhaoStep.Items.FindByText(item);
                   if (li != null)
                       li.Selected = true;
                }

                //
                xe = document.SelectSingleNode("//要求资质等级") as XmlElement;
                tbNeedLevel.Text = Util.ReturnXml(xe.InnerText);
                xe = document.SelectSingleNode("//招标代理单位") as XmlElement;
                tbZhaoDaili.Text = Util.ReturnXml(xe.InnerText);

                
                xe = document.SelectSingleNode("//报名时间") as XmlElement;
                tbBaoMingDate.Text = Util.ReturnXml(xe.InnerText);
                
                xe = document.SelectSingleNode("//报名地点") as XmlElement;
                tbBaoMingPlace.Text = Util.ReturnXml(xe.InnerText);

                xe = document.SelectSingleNode("//单位列表") as XmlElement;
                tbContents.Text = Util.ReturnXml(xe.InnerText);


            }
        }

        private string FillContent()
        {
            string template = BLProject.GetTemplate(Provider, "item3.aspx");
            if (template != string.Empty)
            {

                XmlDocument document = new XmlDocument();
                document.LoadXml(template);
                XmlElement xe = document.SelectSingleNode("//招标单位") as XmlElement;
                xe.InnerText = Util.ReplaceXml(tbZhaobiaoDept.Text.Trim());
                xe = document.SelectSingleNode("//招标项目") as XmlElement;
                xe.InnerText = Util.ReplaceXml(tbProjectName.Text.Trim());
                xe = document.SelectSingleNode("//招标地点") as XmlElement;
                xe.InnerText = Util.ReplaceXml(tbPlace.Text.Trim());
                xe = document.SelectSingleNode("//招标阶段") as XmlElement;

                string temp = string.Empty;
                foreach (ListItem item in cbZhaoStep.Items)
                {
                    if (item.Selected)
                    {
                        temp += "|" + item.Text;
                    }
                }
                temp = temp.Trim(new char[] { '|' });

                xe.InnerText = temp;
                xe = document.SelectSingleNode("//要求资质等级") as XmlElement;
                xe.InnerText = Util.ReplaceXml(tbNeedLevel.Text.Trim());
                xe = document.SelectSingleNode("//招标代理单位") as XmlElement;
                xe.InnerText = Util.ReplaceXml(tbZhaoDaili.Text.Trim());
                xe = document.SelectSingleNode("//报名时间") as XmlElement;
                xe.InnerText = Util.ReplaceXml(tbBaoMingDate.Text.Trim());
                xe = document.SelectSingleNode("//报名地点") as XmlElement;
                xe.InnerText = Util.ReplaceXml(tbBaoMingPlace.Text.Trim());

                xe = document.SelectSingleNode("//单位列表") as XmlElement;
                xe.InnerText = Util.ReplaceXml(tbContents.Text.Trim());
                return document.OuterXml;
            }
            else
                return string.Empty;

        }
       
    }
}
